from django.contrib import messages
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render, redirect
from pymysql import Connect
from keshisizhang.fengzhuan import f1,f2,f3,f4,f5,f6,f7,f8
from keshisizhang.connect import connect
conn = connect()
print(conn)
#登录逻辑处理
def do_login(request):
    username = request.POST["username"]
    password = request.POST.get("password")
    print("用户名和密码分别是：", username, password)
    # sql = """SELECT * FROM emp where name = '""" + username + """' and pwd = '""" + password + """'"""
    sql = """SELECT * FROM user_info where username = %s and password = %s"""
    print("待执行的sql语句：", sql)
    cur = conn.cursor()
    cur.execute(sql, (username, password))#执行sql语句
    data = cur.fetchall()
    print("获取到的数据：", data)
    if len(data) == 1:
        # return HttpResponseRedirect("/shujutiqu")  # 重定向url
        d1_1 = f1()[0]
        d1_2 = f1()[1]
        d2 = f2()
        d3 = f3()
        d4 = f4()
        d5 = f5()
        d6 = f6()
        d7_1 = f7()[0]
        d7_2 = f7()[1]
        d7_3 = f7()[2]
        d8 = f8()
        context = {'date': d1_2, 'time': d1_1, 'shandian': d2, 'rate': d3, 'map': d8, 'bin': d4, 'he': d5, 'cy': d6,
                   'map1': d7_1,
                   'map2': d7_2, 'zyu': d7_3}
        return render(request, 'index.html', context=context
                      )
    #23到37行代码是把fengzhuan.py封装的数据通过render把数据传到index.html中


    if len(data)==0:
        messages.error(request, "账号或密码错误！，请重新输入")
        return render(request, "login.html")

def nsc(request):
    return render(request, "login.html", {"msg": "欢迎您"})



















